<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <script>
            cars = ["BMW", "Volvo", "Saab", "Ford"];
            for (var i = 0; i < cars.length; i++) {
                document.write(cars[i] + "<br>");
            }
        </script>
    </div>
    <hr>
    <div>
        <script>
            cars = ["BMW", "Volvo", "Saab", "Ford"];
            var i = 0, len = cars.length;
            for (; i < len;) {
                document.write(cars[i] + "<br>");
                i++;
            }
        </script>
    </div>
    <hr>
    <div>
        <p>点击下面的按钮，循环遍历对象 "person" 的属性。</p>
        <button onclick="myFunction()">点击这里</button>
        <p id="demo"></p>
        <script>
            function myFunction() {
                var x;
                var txt = "";
                var person = { fname: "Bill", lname: "Gates", age: 56 };
                for (x in person) {
                    txt = txt + person[x];
                }
                document.getElementById("demo").innerHTML = txt;
            }
        </script>
    </div>
</body>

</html>